/*
 * Copyright (c) 2022, tyustli
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2022-03-08     tyustli      first implementation
 */

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

struct time_struct
{
    int hour;
    int min;
    int sec;
};

static void diff_time(struct time_struct start_time, struct time_struct end_time, struct time_struct *diff_time); /* 计算两个时间段的差值 */

int main(int argc, char *argv[])
{
    struct time_struct start_time;
    struct time_struct end_time;
    struct time_struct sub_time = {0, 0, 0};

    printf("输入开始时间：\r\n");
    printf("输入时分秒：\r\n");
    scanf("%d %d %d", &start_time.hour, &start_time.min, &start_time.sec);

    printf("输入结束时间：\r\n");
    printf("输入时分秒：\r\n");
    scanf("%d %d %d", &end_time.hour, &end_time.min, &end_time.sec);

    diff_time(start_time, end_time, &sub_time);

    printf("diff time is: hour:%d min:%d sec:%d\r\n", sub_time.hour, sub_time.min, sub_time.sec);

    return 0;
}

static void diff_time(struct time_struct start_time, struct time_struct end_time, struct time_struct *diff_time)
{
    if(start_time.sec < end_time.sec)
    {
        start_time.min--;
        start_time.sec += 60;
    }

    diff_time->sec = start_time.sec - end_time.sec;

    if(start_time.min < end_time.min)
    {
        start_time.hour--;
        start_time.min += 60;
    }

    diff_time->min = start_time.min - end_time.min;
    diff_time->hour = start_time.hour  - end_time.hour;

    return;
}

/************************ end of time ************************/
